package com.iflytek.universitymanagement.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.iflytek.universitymanagement.domain.CourseResource;
import com.iflytek.universitymanagement.domain.Resource;
import com.iflytek.universitymanagement.mapper.ResourceMapper;
import com.iflytek.universitymanagement.service.ResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ResourceServiceImpl extends ServiceImpl<ResourceMapper, Resource> implements ResourceService {

    @Autowired
    private ResourceMapper resourceMapper;
    @Override
    public List<CourseResource> getAllResourcesWithCourseName() {
        return resourceMapper.getAllResourcesWithCourseName();
    }

    @Override
    public boolean createResource(Resource resource) {
        // 使用 MyBatis-Plus 提供的 insert 方法
        return save(resource);  // save 方法会调用 insert 操作
    }

    @Override
    public List<Resource> findResourcesByCourseId(int courseId) {
        return baseMapper.selectList(new QueryWrapper<Resource>().eq("course_id", courseId));
    }

}